﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace FantasyDraft
{
    class Team
    {
        private List<Player> players;
        private Random random = new Random();
        private string teamName;
        private Player player1; 

        public Team()
        {
            players = new List<Player>();
            for (int player = 1; player <= 10; player++)
            {
                player1 = new Player(player, 0);
                players.Add(player1);
            }
            for (int player = 1; player <= 10; player++)
            {
                player1 = new Player(player, 1);
                players.Add(player1);
            }
            for (int player = 1; player <= 10; player++)
            {
                player1 = new Player(player, 2);
                players.Add(player1);
            }
        }

        public Team(IEnumerable<Player> initialPlayers, string team)
        {
            players = new List<Player>(initialPlayers);
            teamName = team;
        }

        public int Count { get { return players.Count; } }

        public void Add(Player playerToAdd)
        {
            players.Add(playerToAdd);
        }

        public Player Deal(int index)
        {
            Player PlayerToDeal = players[index];
            players.RemoveAt(index);
           
            return PlayerToDeal;
        }

        public Player CheckDuplicate(int index)
        {
            Player PlayerToDeal = players[index];
            return PlayerToDeal;
        }

        public void Randomize()
        {
            List<Player> NewPlayers = new List<Player>();
            while (players.Count > 0)
            {
                int PlayerToMove = random.Next(players.Count);
                NewPlayers.Add(players[PlayerToMove]);
                players.RemoveAt(PlayerToMove);
            }
            players = NewPlayers;
        }

        public IEnumerable<string> GetPlayerNames()
        {
            string[] PlayerNames = new string[players.Count];
            for (int i = 0; i < players.Count; i++)
                PlayerNames[i] = players[i].Name;
            return PlayerNames;
        }

        public IEnumerable<Positions> GetPlayerPositions()
        {
            Positions[] PlayerPositions = new Positions[players.Count];
            for (int i = 0; i < players.Count; i++)
                PlayerPositions[i] = players[i].Position;
            return PlayerPositions;
        }
         

        public string Name
        {
            get
            {
                return teamName;
            }
        }
    }
}
